package cn.xspace.wnx.db;

import android.content.Context;

import java.util.ArrayList;

import cn.xspace.wnx.data.IOrgUserData;
import cn.xspace.library.bean.OrgDeptUserBean;
import rx.Observable;
import rx.Subscriber;

/**
 * Created by liuchen on 2016/10/26.
 */

public class OrgAllUserDao {

    private Context context;
    private static OrgAllUserDao instance;
    public static final String TABLE_NAME = "t_addressbook_list";

    public static OrgAllUserDao getInstance() {
        if (instance == null) {
            instance = new OrgAllUserDao();
        }
        return instance;
    }

    private OrgAllUserDao() {
    }

    public static final String COLUMN_FRIEND_ID = "friend_id";
    public static final String COLUMN_FRIEND_NAME = "friend_name";
    public static final String COLUMN_FRIEND_LOGO = "friend_logo";
    public static final String COLUMN_FRIEND_DEPT_ID = "friend_dept_id";
    public static final String COLUMN_FRIEND_DEPT_NAME = "friend_dept_name";
    public static final String COLUMN_FRIEND_SEX = "friend_sex";

    public static final String ORG_USER_TABLE_CREATE = "CREATE TABLE  IF NOT EXISTS "
            + OrgAllUserDao.TABLE_NAME
            + " (_ID INTEGER PRIMARY KEY AUTOINCREMENT,"
            + OrgAllUserDao.COLUMN_FRIEND_ID + " TEXT,"
            + OrgAllUserDao.COLUMN_FRIEND_NAME + " TEXT,"
            + OrgAllUserDao.COLUMN_FRIEND_LOGO + " TEXT,"
            + OrgAllUserDao.COLUMN_FRIEND_DEPT_ID + " TEXT,"
            + OrgAllUserDao.COLUMN_FRIEND_SEX + " TEXT,"
            + OrgAllUserDao.COLUMN_FRIEND_DEPT_NAME + " TEXT)";

    public void insertOrUpdate(OrgDeptUserBean bean) {
        WNXDBManager.getInstance().insertOrgUser(bean);
    }

    public IOrgUserData getOrgUserData() {
        return orgUserData;
    }

    IOrgUserData orgUserData = new IOrgUserData() {
        @Override
        public Observable<String> insertOrUpdate(OrgDeptUserBean model) {
            return null;
        }

        @Override
        public Observable<ArrayList<OrgDeptUserBean>> getOrgUserList() {
            return Observable.create(new Observable.OnSubscribe<ArrayList<OrgDeptUserBean>>() {
                @Override
                public void call(Subscriber<? super ArrayList<OrgDeptUserBean>> subscriber) {
                    ArrayList<OrgDeptUserBean> beanList = WNXDBManager.getInstance().getOrgUserList();
                    subscriber.onNext(beanList);
                    subscriber.onCompleted();
                }
            });
        }
    };


}
